package cn.shop.dys.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.bean.GrideViewItem;
import cn.shop.dys.bean.Product;
import cn.shop.dys.constant.CommonConstant;
import cn.shop.dys.constant.DBConstants;
import cn.shop.lib_common.ComViewHolder;


/**
 * Created by Administrator on 2016/4/19.
 */
public class GridViewAdapter extends BaseAdapter {
    List<Product> list;
    Context context;

    public GridViewAdapter(Context context, List<Product> list) {
        this.list = list;
        this.context = context;
        Log.d("test",list.size()+"");
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Product getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ComViewHolder holder = ComViewHolder.newInstance(context, convertView, R.layout.grideview_item);
        Product item = getItem(position);
        String url = CommonConstant.HOST + item.pic;
        Glide.with(context)
                .load(url)
                .fitCenter()
                .crossFade()
                .into(holder.getIv(R.id.iv_item_grideview));
        holder.getTv(R.id.tv_item_grideview).setText(item.name);

        return holder.getView();
    }
}
